//
//  MCDiscountPayCell.swift
//  StoreManage
//
//  Created by MC on 2017/12/19.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCChangeStoreCell: UITableViewCell {
    
    
    var model : MCChangeStoreModel = MCChangeStoreModel() {
        didSet {
          iconImageView.sd_setImage(with: URL.init(string: model.logoPath), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
            nameLabel.text = model.storeName
            
            if model.storeId == MCUserinfo_getStoreId() {
                statusButton.isSelected = true
            } else {
                statusButton.isSelected = false
            }
        }
    }
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = UIColor.white
        
        self.addSubview(bgImageView)
        bgImageView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(5, 15, 0, 15))
        }
        
        bgImageView.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(self)
            make.left.equalTo(10)
            make.size.equalTo(CGSize.init(width: 70, height: 70))
        }
        
        bgImageView.addSubview(statusButton)
        statusButton.snp.remakeConstraints { (make) ->Void in
            make.right.equalTo(bgImageView).offset(-10)
            make.centerY.equalTo(bgImageView)
            make.size.equalTo(CGSize.init(width: 20, height: 20))
        }
        
        bgImageView.addSubview(nameLabel)
        nameLabel.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(iconImageView.snp.right).offset(10)
            make.right.equalTo(statusButton.snp.left).offset(-10)
            make.centerY.equalTo(bgImageView)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var bgImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Store_changeBg")
        return imageView
    }()
    
    lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.cornerRadius = 35
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = UIColor.MCGray_light.cgColor
        imageView.layer.borderWidth = 1
        return imageView
    }()

    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = MCFont(14)
        label.textColor = UIColor.black
        return label
    }()
    
    lazy var statusButton : UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "Reuse_selected"), for: UIControlState.normal)
        button.setImage(#imageLiteral(resourceName: "Reuse_selectedSign"), for: UIControlState.selected)
        return button
    }()
}




